﻿using System;
using System.Collections.Generic;
using System.Text;
using He.Common;
using LitJson;

namespace He.API.WeiXin
{
    public class MenuHandle
    {
        /// <summary>
        /// 请求生成菜单
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static string ResponseMenu(string json)
        {
            string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + CheckSignature.GetAccessToken();
            string result = HttpHelper.HttpPost(url, json);
            Dictionary<string, object> dic = JsonMapper.ToObject<Dictionary<string, object>>(result);
            return dic["errmsg"].ToString();
        }

        /// <summary>
        /// 对菜单的URL进行处理
        /// </summary>
        /// <param name="url"></param>
        /// <param name="siteDomain"></param>
        /// <returns></returns>
        public static string HandleUrl(string url, string siteDomain)
        {
            if (url.StartsWith("http://"))
            {
                return url;
            }
            else
            {
                return string.Format("http://{0}{1}", siteDomain.Trim('/'), url);
            }
        }
    }
}
